using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class forums_controls_usercp_pm_viewPM : Controls.DataManagerPrivateMessageControl
{
    public delegate void ReplyDelegate(object sender, DAL.PrivateMessage msg);
    public delegate void QuoteDelegate(object sender, DAL.PrivateMessage msg);

    public event ReplyDelegate Reply;
    public event QuoteDelegate Quote;

    protected DAL.User CurrentUser
    {
        get
        {
            return Managers.UserLoginManager.CurrentUser;
        }
    }

    protected override void ItemChanged()
    {
        if (CurrentMessage != null)
        {
            mviewMsg.SetActiveView(viewMessage);
            Page.Title = "FSTDT Forums: " + "View Message";
            lnkFrom.Text = Helpers.StringHelper.SafeFormat(CurrentMessage.From.Username);
            lnkFrom.NavigateUrl = Helpers.StringHelper.SafeFormat("~/forums/profile.aspx?u={0}", CurrentMessage.From.ID);

            lnkTo.Text = Helpers.StringHelper.SafeFormat(CurrentMessage.To.Username);
            lnkTo.NavigateUrl = Helpers.StringHelper.SafeFormat("~/forums/profile.aspx?u={0}", CurrentMessage.To.ID);

            if (CurrentMessage.From.AdminSettings.AllowAvatar && CurrentMessage.From.HasAvatar && CurrentUser.UserSettings.ShowUserAvatars)
            {
                imgAvatar.Visible = true;
                imgAvatar.ImageUrl = Helpers.StringHelper.SafeFormat("~/forums/avatars/{0}.{1}", CurrentMessage.From.ID, CurrentMessage.From.AvatarExtension);
            }
            else
            {
                imgAvatar.Visible = false;
            }

            lblSubject.Text = Helpers.StringHelper.SafeFormat(CurrentMessage.Subject);
            lblMessage.Text = DAL.YCodes.Format(CurrentMessage.Message);

            if (CurrentMessage.To == Managers.UserLoginManager.CurrentUser && CurrentMessage.MsgRead == false)
            {
                CurrentMessage.MsgRead = true;
                DAL.PrivateMessages.Save(CurrentMessage);
            }
        }
        else
        {
            mviewMsg.SetActiveView(viewError);
            Page.Title = "FSTDT Forums: " + "Oops!";
        }
    }
    protected void NewReply(object sender, CommandEventArgs e)
    {
        if (Reply != null)
        {
            Reply(this, CurrentMessage);
        }
    }
    protected void NewQuote(object sender, CommandEventArgs e)
    {
        if (Quote != null)
        {
            Quote(this, CurrentMessage);
        }
    }
}
